package com.chicken.controller;

import com.chicken.dto.model.Product;
import com.chicken.pojo.IndexData;
import com.chicken.vo.BaseResponseVO;
import com.jfinal.core.Controller;
import com.sun.xml.internal.rngom.parse.host.Base;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author zewei.wang
 * @date 2018/4/4.
 */
public class IndexController extends Controller {


    public void index(){
        render("index.html");

    }

    public void indexData(){
        List<Product> products = Product.dao.find("select * from product");
        List<IndexData> resultList = new ArrayList<>();
        products.forEach(item->{
            IndexData indexData = new IndexData();
            Random random = new Random();
            int count = random.nextInt(1000)+100;
            double persent = random.nextFloat();
            indexData.setImageUrl(item.getCardImage());
            indexData.setName(item.getName());
            indexData.setPersent(""+persent);
            indexData.setRemark(item.getRemark());
            indexData.setScale(item.getScale());
            indexData.setCount(count);
            resultList.add(indexData);
        });
        BaseResponseVO baseResponseVO = new BaseResponseVO();
        baseResponseVO.setSucced();
        baseResponseVO.setData(resultList);
        renderJson(baseResponseVO);
    }
}

